package com.exampl.springstack.common.exceptionUtils.advice;

import com.exampl.springstack.common.exceptionUtils.exception.SystemException;
import com.exampl.springstack.common.exceptionUtils.vo.ResponseResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author Qiangfanghao
 * advice spring3.2捕获 自定义异常
 */
@ControllerAdvice
public class SpringControllerAdvice {

    /**
     * 捕获自定义异常 SystemException
     * 返回的结果为 将自定义的异常封装到 自定义ExceptionResult 用于异常的错误码 错误信息 以及时间戳
     */
    @ExceptionHandler(SystemException.class)
    public ResponseEntity<ResponseResult> handleException(SystemException e){
        return ResponseEntity.status(e.getHttpStatus()).body(new ResponseResult(e));
    }



}
